Remove try-finally from @with_pool for inlining performance#32
Merged
Remove try-finally from @with_pool for inlining performance#32
try-finally from @with_pool for inlining performance#32Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Julia cannot inline functions containing
try-finally. This blocks the compiler from optimizing@inline @with_poolfunctions in hot loops.Removing
try-finallyyields ~15-25% speedup on typical patterns (single/nested/multi-type), with larger gains on Julia 1.10 LTS. LLVM IR confirms the exception handler frame is completely eliminated.What Changed
@with_poolnow uses direct rewind insertion instead oftry-finally:rewind!inserted at every exit point: implicit return, explicitreturn,break,continuewhile pool._current_depth > _entry_depth + 1) for deferred recovery when inner scope throws and outer catches@gotosafety: compile-time hard error on external jumps (set-difference analysis of goto targets vs local labels)The old
try-finallybehavior is preserved as@safe_with_pool/@safe_maybe_with_pool.API
@with_pool@safe_with_pooltry-finally@maybe_with_pool@safe_maybe_with_pooltry-finally+ runtime toggleException Contract
@with_pool@safe_with_poolreset!needed)